<template>
  <div class="top top_content ft_PingFangSC">
    <div class="left">
      <p class="subTitle ft_PingFangSC">房地产商品房交易</p>
      <div class="year_content">
        <div class="years">
          <span class="active">2019</span>
        </div>
        <div class="content">
          <div class="left">
            <div class="img">
              <p class="number">
                <countTo :endVal="getNumber(fdc_zcjje)" />
                <!-- {{ fdc_zcjje>10000? Math.ceil(fdc_zcjje/10000):Math.ceil(fdc_zcjje)}} -->
              </p>
              <p>总成交({{ fdc_zcjje>10000?"亿元":"万元"}})</p>
            </div>
          </div>
          <div class="right">
            <p>各区成交金额数</p>
            <div v-for="(item,index) in cjje" :key="index">
              {{item.name}}
              <CapsuleChart :value="item.percent" />
              <span class="number">
                <countTo :endVal="getNumber(item.value)" />
                <!-- {{item.value>10000? Math.ceil(item.value/10000):Math.ceil(item.value)}} -->
              </span>
              {{ item.value>10000?"亿元":"万元"}}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="line"></div>
    <div class="right">
      <p class="subTitle ft_PingFangSC">房地产企业人员</p>
      <div class="year_content">
        <div class="years">
          <span
            @click="changeCurrentYear(index)"
            :class="activeYear==index?'active':''"
            v-for="(item,index) in years"
            :key="index"
          >{{ item }}</span>
        </div>
        <Rotation
          :w="40"
          :w_unit="'rem'"
          :h="'22.154rem'"
          :len="years.length"
          :current="activeYear"
          @changeCurrent="changeCurrentYear"
        >
          <PerSaleContent v-for="(item,index) in years" :key="index" :year="item" />
        </Rotation>
        <!-- <div class="content">
                    <div>
                        <p>开发商总数</p>
                        <div class="data">
                            <div class="rule">
                                <Rule :number="12530" />
                            </div>
                            <div>
                                <span class="dDigital_number">12530</span>家
                            </div>
                        </div>
                    </div>
                    <div>
                        <p>项目总数</p>
                        <div class="data">
                            <div class="rule">
                                <Rule :number="9640" />
                            </div>
                            <div>
                                <span class="dDigital_number">9640</span>个
                            </div>
                        </div>
                    </div>
                    <div>
                        <p>经纪机构数</p>
                        <div class="data">
                            <div class="rule">
                                <Rule :number="17260" />
                            </div>
                            <div>
                                <span class="dDigital_number">17260</span>家
                            </div>
                        </div>
                    </div>
                    <div>
                        <p>经纪人总数</p>
                        <div class="data">
                            <div class="rule">
                                <Rule :number="32530" />
                            </div>
                            <div>
                                <span class="dDigital_number">32530</span>人
                            </div>
                        </div>
                    </div>
        </div>-->
      </div>
    </div>
  </div>
</template>

<script>
import CapsuleChart from "./capsuleChart";
import Rotation from "@/components/common/Rotation";
import PerSaleContent from "./perSale";
export default {
  name: "LeftTop",
  components: {
    CapsuleChart,
    PerSaleContent,
    Rotation
  },
  data: () => {
    return {
      fdc_zcjje: 0,
      cjje: [
        { name: "南湖区", value: 0, percent: "0%" },
        { name: "秀洲区", value: 0, percent: "0%" },
        { name: "经开区", value: 0, percent: "0%" }
      ],
      years: [],
      activeYear: -1
    };
  },
  methods: {
    getNumber(val) {
      if (val > 10000) {
        return Math.ceil(val / 10000);
      }
      return Math.ceil(val);
    },
    changeCurrentYear(index) {
      this.activeYear = index;
    },
    getData() {
      const _self = this;
      this.http
        .post("", {
          path: "ov",
          groupid: 20
        })
        .then(res => {
          if (!(Object.getOwnPropertyNames(res.data) == 0 || res.data == "")) {
            const {
              fdc_cjje_jk,
              fdc_cjje_nh,
              fdc_cjje_xz,
              fdc_zcjje
            } = res.data;
            _self.fdc_zcjje = fdc_zcjje ? fdc_zcjje : 0;
            _self.cjje = [
              {
                name: "南湖区",
                value: fdc_cjje_nh ? fdc_cjje_nh : 0,
                percent:
                  (!fdc_zcjje ? 0 : (fdc_cjje_nh / fdc_zcjje).toFixed(2)) + "%"
              },
              {
                name: "秀洲区",
                value: fdc_cjje_xz ? fdc_cjje_xz : 0,
                percent:
                  (!fdc_cjje_xz ? 0 : (fdc_cjje_xz / fdc_zcjje).toFixed(2)) +
                  "%"
              },
              {
                name: "经开区",
                value: fdc_cjje_jk ? fdc_cjje_jk : 0,
                percent:
                  (!fdc_cjje_xz ? 0 : (fdc_cjje_xz / fdc_zcjje).toFixed(2)) +
                  "%"
              }
            ];
          }
        });
    }
  },
  mounted() {
    this.getData();
  },
  beforeMount() {
    var currentY = new Date().getFullYear();
    this.years = Array.from(Array(2)).map((item, index) => currentY - index);
  }
};
</script>

<style lang="scss" scoped>
.top_content {
  display: flex;
  padding: 1.2rem 0;
  .number {
    font-family: DINAlternateBold;
  }
  > .left {
    width: 55%;
    position: relative;
    .year_content {
      width: 100%;
      .years {
        padding-right: 1rem;
      }
      .content {
        margin-top: 2rem;
        display: flex;
        .left {
          margin-left: 2rem;
          margin-top: 4rem;
          margin-right: 3rem;
          display: inline-block;
          .img {
            width: 13.69rem;
            height: 13.69rem;
            background: url("../../../assets/background/estate/bg_AmountOfTransactions.png")
              no-repeat center;
            background-size: 100% 100%;
            padding-top: 4rem;
            > p {
              text-align: center;
              font-size: 1.077rem;
              color: #bed7fa;
              line-height: 1.3em;
            }
            .number {
              font-size: 2.15rem;
              color: orange;
              line-height: 1.5em;
            }
          }
        }
        .right {
          margin-top: 2rem;
          display: inline-block;
          p {
            color: #2bb7ff;
            font-size: 1.23rem;
          }
          > div {
            font-size: 1.077rem;
            color: #bed7fa;
            line-height: 5em;
            .number {
              font-size: 1.846rem;
              color: #fff;
              letter-spacing: 0.0625em;
              text-align: center;
              display: inline-block;
              width: 8rem;
            }
          }
        }
      }
    }
  }
  .line {
    width: 1px;
    height: 24rem;
    margin-top: 1.3rem;
    background: #00ecff4d;
  }
  > .right {
    position: relative;
    margin-left: 2rem;
    .year_content {
      width: 40rem;
    }
  }
}
</style>